package com.aloda.ojquestion.controller.inner;

import com.aloda.ojcommon.domain.entity.Question;
import com.aloda.ojquestion.service.QuestionService;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @Author aloda
 * @Date 2025/4/29 14:43
 */
@RestController
@RequestMapping("/question/inner")
public class QuestionInnerController {

    @Resource
    private QuestionService questionService;

    @GetMapping("/{id}")
    public Question getById(@PathVariable Long id) {
        return questionService.getById(id);
    }

    @PutMapping("/{id}")
    public void addAcceptedNum(@PathVariable Long id) {
        // 新增通过数量
        LambdaUpdateWrapper<Question> wrapper = new LambdaUpdateWrapper<>();
        wrapper.eq(Question::getId, id)
                .setIncrBy(Question::getAcceptedNum, 1);
        questionService.update(wrapper);
    }
}
